import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)

const store = new Vuex.Store({
  // strict: process.env.NODE_ENV !== 'production',
  state: {
    count: 0,
    Authorization: window.localStorage.getItem('Authorization') ? window.localStorage.getItem('Authorization') : ''
  },
  // 相当于组件中的方法，但不能使用异步方法
  mutations: {
    increment(state, payload) {
      state.count += payload
    },
    changeLogin(state, user) {
      state.Authorization = user.Authorization
      window.localStorage.setItem('Authorization', user.Authorization)
    }
  },
  getters: {
    getNum(state) {
      return state.count
    }
  },
  // 组件中使用dispatch方法调用
  actions: {
    increment(content) {
      console.log('action.content :>> ', content)
      content.commit('increment')
    }
  },
  modules: {}
})

export default store
